package com.kaibes.web.admin;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class AdminBoxInit implements InitializingBean {

	@Autowired(required = false)
    private List<IconBox> iconBoxs;
	
	@Bean
    public List<IconBox> iconBoxs() {
        if (iconBoxs == null) {
            return new ArrayList<>();
        } else {
            return iconBoxs;
        }
    }
	
	public void addIconBox(IconBox iconBox) {
        if (iconBoxs == null) {
            iconBoxs = new ArrayList<>();
        }
        iconBoxs.add(iconBox);
        Collections.sort(iconBoxs);
    }
    
    public List<IconBox> getIconBoxs() {
        return iconBoxs;
    }
    
	@Override
	public void afterPropertiesSet() throws Exception {
		if (iconBoxs != null) {
            Collections.sort(iconBoxs);
            List<IconBox> temp = iconBoxs();
            if (temp != iconBoxs) {
                temp.addAll(iconBoxs);
            }
        }
	}
}
